#include "OxideWrapper.h"
#include <QQuickWindow>
#include <QGuiApplication>
#include <QStyleHints>
#include <QDebug>

OxideOverlay::OxideOverlay(QQuickItem *parent) : QQuickItem(parent), m_listView(0)
{
    setFiltersChildMouseEvents(true);
}

QQuickItem *OxideOverlay::listView() const
{
    return m_listView;
}

void OxideOverlay::listView(QQuickItem *listView)
{
    if (m_listView == listView)
        return;

    m_listView = listView;
    emit listViewChanged(listView);
}

void OxideOverlay::wheelEvent(QWheelEvent *event)
{
    // Don't let oxide pinch this wheel event
    // we want the listview flickable to have this one
    event->accept();
    window()->sendEvent(m_listView, event);
}

void OxideOverlay::touchEvent(QTouchEvent *event)
{
    // Oxide is our parent here so we need to both send this
    // Event directly to it but also propogate the event so that
    // QQuickFlickable can still filter it as a child event otherwise
    // it get's blocked.
    event->accept();
    QQuickItem *item = static_cast<QQuickItem *>(parent());
    window()->sendEvent(item, event);
    return QQuickItem::touchEvent(event);
}

bool OxideOverlay::childMouseEventFilter(QQuickItem *item, QEvent *event)
{
    Q_UNUSED(item);
    QQuickItem *p = static_cast<QQuickItem *>(parent());
    // all we care about her is posting the events back to oxide
    // and catch the wheel events above to send back to the flickable
    window()->sendEvent(p, event);
    return false;
}
